/*
*  Copyright 2019-2023 CY
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.ejweixin.rest;

import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.ejweixin.domain.NgCompanyNewsTitle;
import me.zhengjie.modules.ejweixin.service.NgCompanyNewsTitleService;
import me.zhengjie.modules.ejweixin.domain.vo.NgCompanyNewsTitleQueryCriteria;
import lombok.RequiredArgsConstructor;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author cy
* @date 2025-04-24
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "公司动态标题管理")
@RequestMapping("/api/ngCompanyNewsTitle")
public class NgCompanyNewsTitleController {

    private final NgCompanyNewsTitleService ngCompanyNewsTitleService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('ngCompanyNewsTitle:list')")
    public void exportNgCompanyNewsTitle(HttpServletResponse response, NgCompanyNewsTitleQueryCriteria criteria) throws IOException {
        ngCompanyNewsTitleService.download(ngCompanyNewsTitleService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询公司动态标题")
    @ApiOperation("查询公司动态标题")
    @PreAuthorize("@el.check('ngCompanyNewsTitle:list')")
    public ResponseEntity<PageResult<NgCompanyNewsTitle>> queryNgCompanyNewsTitle(NgCompanyNewsTitleQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(ngCompanyNewsTitleService.queryAll(criteria,page),HttpStatus.OK);
    }

    @GetMapping("getTitleList")
    @Log("查询公司动态标题")
    @ApiOperation("查询公司动态标题")
    @AnonymousAccess
    public ResponseEntity<List<NgCompanyNewsTitle>> getTitleList(NgCompanyNewsTitleQueryCriteria criteria){
        return new ResponseEntity<>(ngCompanyNewsTitleService.queryAll(criteria),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增公司动态标题")
    @ApiOperation("新增公司动态标题")
    @PreAuthorize("@el.check('ngCompanyNewsTitle:add')")
    public ResponseEntity<Object> createNgCompanyNewsTitle(@Validated @RequestBody NgCompanyNewsTitle resources){
        ngCompanyNewsTitleService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改公司动态标题")
    @ApiOperation("修改公司动态标题")
    @PreAuthorize("@el.check('ngCompanyNewsTitle:edit')")
    public ResponseEntity<Object> updateNgCompanyNewsTitle(@Validated @RequestBody NgCompanyNewsTitle resources){
        ngCompanyNewsTitleService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除公司动态标题")
    @ApiOperation("删除公司动态标题")
    @PreAuthorize("@el.check('ngCompanyNewsTitle:del')")
    public ResponseEntity<Object> deleteNgCompanyNewsTitle(@RequestBody List<Integer> ids) {
        ngCompanyNewsTitleService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}